package net.carinae.dev.seduku.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;

/**
 * Stores the changes in the Sudoku created by the client.
 * 
 * Note: The user sends a String so this object stores a string, when processing
 * the changes, one of the steps will be to try to translate that string to a
 * valid digit.
 * 
 * @author Carlos Vara
 */
public class Sudoku4Changes implements Serializable {

	private HashMap<String,String> changes = new HashMap<String, String>();
	

	/**
	 * Sets a proposed square value.
	 * 
	 * @param square The index of the square to set
	 * @param d The digit to be set in the square
	 */
	public void setSquare(String square, String value) {
		if ( 0 > Arrays.binarySearch(Sudoku4.SQUARES, square) ) {
			throw new IllegalArgumentException("Invalid square index: " + square);
		}
		this.changes.put(square, value);
	}
	
	
	/**
	 * @return A key (square index), value (proposed string) list representing
	 * the changes submitted by the user.
	 */
	public HashMap<String,String> getListOfChanges() {
		return new HashMap<String, String>(this.changes);
	}
	
	
	/**
	 * Erases all the changes.
	 */
	public void reset() {
		this.changes.clear();
	}
	
	@Override
	public String toString() {
		return this.changes.toString();
	}
	
	
}
